package com.driving.code.utils;


import redis.clients.jedis.Jedis;

import java.util.Random;


public class EmailCodeUtil {
    public static String getCode(){
        Random random = new Random();
        String code="abcdefghijklmnopqrstuvwxyjABCDEFGHIJKLMNOPQRSTUVWXYJ0123456789";
        StringBuilder code1 = new StringBuilder();
        for (int i = 0; i < 5; i++) {
            char c = code.charAt(random.nextInt(61));
            code1.append(c);
        }
        return code1.toString();
    }
    public static void setVeriCode(String email,String code){
        Jedis jedis = new Jedis("127.0.0.1", 6379);
        String codeeKey=email+"code";
        jedis.setex(codeeKey,120,code);
        jedis.close();
    }
    public static  boolean checkCode(String email,String code){
        Jedis jedis = new Jedis("127.0.0.1", 6379);
        String redisCode = jedis.get(email + "code");
        return redisCode.equals(code);
    }
}
